#include <Windows.h>
#include <mhook-2.4/mhook-2.4/mhook-lib/mhook.h>
#ifdef _DEBUG
#pragma comment(lib, "mhook-2.4/mhook-2.4/lib/mhook-2.4d.lib")
#else
#pragma comment(lib, "mhook-2.4/mhook-2.4/lib/mhook-2.4.lib")
#endif


typedef
BOOL (WINAPI *MHOOK_PTR_API(DeviceIoControl))(
	_In_ HANDLE hDevice,
	_In_ DWORD dwIoControlCode,
	_In_reads_bytes_opt_(nInBufferSize) LPVOID lpInBuffer,
	_In_ DWORD nInBufferSize,
	_Out_writes_bytes_to_opt_(nOutBufferSize, *lpBytesReturned) LPVOID lpOutBuffer,
	_In_ DWORD nOutBufferSize,
	_Out_opt_ LPDWORD lpBytesReturned,
	_Inout_opt_ LPOVERLAPPED lpOverlapped
	);


//MHOOK_DEFINITION(DeviceIoControl);
MHOOK_DEFINITION(Kernel32.dll, DeviceIoControl);

BOOL WINAPI MHOOK_USER_API(DeviceIoControl)(
	_In_ HANDLE hDevice,
	_In_ DWORD dwIoControlCode,
	_In_reads_bytes_opt_(nInBufferSize) LPVOID lpInBuffer,
	_In_ DWORD nInBufferSize,
	_Out_writes_bytes_to_opt_(nOutBufferSize, *lpBytesReturned) LPVOID lpOutBuffer,
	_In_ DWORD nOutBufferSize,
	_Out_opt_ LPDWORD lpBytesReturned,
	_Inout_opt_ LPOVERLAPPED lpOverlapped
	)
{
	BOOL result = MHOOK_ORG_API(DeviceIoControl)(
		hDevice, 
		dwIoControlCode, 
		lpInBuffer, 
		nInBufferSize, 
		lpOutBuffer, 
		nOutBufferSize, 
		lpBytesReturned, 
		lpOverlapped);

	return result;
}


BOOL SetHook()
{
	MHOOK_SETHOOK_BEGIN;
	MHOOK_SETHOOK(DeviceIoControl);

	MHOOK_SETHOOK_END(UnHook);
	MHOOK_SETHOOK_RETURN;
}

BOOL UnHook()
{
	MHOOK_UNHOOK(DeviceIoControl);
	return TRUE;
}
